﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CubeManager : MonoBehaviour
{
    public Transform anchor;
    public float acceleration =1;//加速度
    public float power = 100;
    Rigidbody2D rig;

    Vector2[] directors=new Vector2[4]{ new Vector2(1,0),
        new Vector2(0,1),new Vector2(-1,0),new Vector2(0,-1)};//四个方向,以x正方向为起点逆时针转
    public int dire = 0;//默认方向为0
    public float decSpeed = 5;//速度过大减速
    float decIndex = 0.9f;
    #region turn left and right move
    /*
    //移动速度与加速度
    public float speed = 1;
    //float addSpeed = 0.5f;

    //旋转速度
    public float rollSpeed = 100;
    int dir = 1;
    // Use this for initialization
    */
    #endregion

    void Start()
    {
            rig = this.GetComponent<Rigidbody2D>();
    }

  void Update()
    {
        #region turn left and right move

        /*
        transform.Translate(transform.up * speed * Time.deltaTime);

        transform.Rotate(transform.forward * dir, rollSpeed * Time.deltaTime);
        // speed += addSpeed * Time.deltaTime;
        if (rig.velocity.magnitude > 0)
        {
            rig.velocity *= 0.9f;
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            dir = -dir;
        }
        */
        #endregion   }
        rig.velocity += (Vector2)transform.up * Time.deltaTime;//add the speed

        if (rig.velocity.magnitude>decSpeed)//速度过大则减速
        {
            rig.velocity *= decIndex;
        }

        if (Input.GetKeyDown(KeyCode.Space))//变向
        {
            transform.Rotate(new Vector3(0, 0, 90));
            dire++;
            dire %= 4;
        }
    }
}
